package com.longrise.android.byjk.plugins.course.batchbuy;

import android.graphics.Color;
import android.view.View;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.android.byjk.R;
import com.longrise.android.byjk.model.AllCourseParentBean;
import com.longrise.common.utils.PrintLog;
import com.longrise.common.utils.UmengStatisticsUtil;

import java.util.List;

/**
 * Created by callxkj on 2017/11/17.
 * 左边的adapter
 */

public class BatchbuyAdapter1 extends BaseQuickAdapter<AllCourseParentBean, BaseViewHolder> {

    private OnItemClickListener mListener;

    private int mCurrentPosition = 0;

    public BatchbuyAdapter1() {
        super(R.layout.item_batchbuy_rcv1, null);
    }

    public void setDatas(List<AllCourseParentBean> beans) {
        setNewData(beans);
    }


    @Override
    protected void convert(final BaseViewHolder helper, AllCourseParentBean item) {
        final int layoutPosition = helper.getLayoutPosition();
        RelativeLayout rlRoot = helper.getView(R.id.item_batchbuy_root);

        helper.setText(R.id.item_batchbuy_tv1, item.getAssortmentname());

        if (mCurrentPosition == layoutPosition) {
            helper.getView(R.id.item_batchbuy_root).setBackgroundColor(Color.parseColor("#FFFFFF"));
            helper.getView(R.id.item_batchbuy_iv1).setVisibility(View.VISIBLE);

        } else {
            helper.getView(R.id.item_batchbuy_root).setBackgroundColor(Color.parseColor("#EBEFF2"));
            helper.getView(R.id.item_batchbuy_iv1).setVisibility(View.GONE);
        }


        final String assortmenttype = item.getAssortmenttype();

        rlRoot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onClick(assortmenttype);
                    mCurrentPosition = layoutPosition;
                    notifyDataSetChanged();
                    UmengStatisticsUtil.onEvent("buy_system" + (helper.getLayoutPosition() + 1));
                }
            }
        });
    }


    public void setOnBatchbuyParentItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }


    interface OnItemClickListener {
        void onClick(String assortmenttypekey);
    }


}
